<?php

declare(strict_types=1);

namespace Wcc\LaravelSupport;

class Str
{
    /**
     * Is string 'true' or bool true
     * 
     * @return \Closure
     */
    public function isFalse()
    {
        return function($false): bool{
            return $false === 'false' || $false === false;
        };
    }

    /**
     * Is json array '[1]'
     * 
     * @return \Closure
     */
    public function isJsonArray()
    {
        return function($json): bool{
            if(!is_string($json)){
                return false;
            }

            if(!is_array(json_decode($json, true))){
                return false;
            }

            return $json[0] === '[';
        };
    }

    /**
     * Is 果json object '{"key":"value"}'
     * 
     * @return \Closure
     */
    public function isJsonObject()
    {
        return function($json): bool{
            if(!is_string($json)){
                return false;
            }

            if(!is_array(json_decode($json, true))){
                return false;
            }

            return $json[0] === '{';
        };
    }

    /**
     * Is string 'null' or null
     * 
     * @return \Closure
     */
    public function isNull()
    {
        return function($null): bool{
            return $null === 'null' || $null === null;
        };
    }

    /**
     * Is string 'false' or bool false
     * 
     * @return \Closure
     */
    public function isTrue()
    {
        return function($true): bool{
            return $true === 'true' || $true === true;
        };
    }
}